﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DBScript
{
    /// <summary>
    /// MsSQL Server 2000
    /// </summary>
    public class MsSQL2kQuery:MsSQLQuery
    {
        public MsSQL2kQuery():base()
        {

        }
        #region 输出SQL
        public override string ExportList()
        {
            if (!string.IsNullOrEmpty(Sql))
            {
                return ExportDeal(Sql);
            }
            StringBuilder strSql = new StringBuilder();
            string strOrder; // -- 排序类型

            strOrder = string.Format("order by {0}", OrderBy);

            string where="";
            if(!string.IsNullOrEmpty(Where))
            {
                where=string.Format(" where {0}",Where);
            }

            strSql.Append(string.Format("select {0} from {1} where {2} in (select top {3} {2} from {1}{4} order by {5}) and {2} not in (select top {6} {2} from {1}{4} order by {5})",
                          Columns, Table, PrimaryKey, LimitFirst + LimitLengh-1,where,  OrderBy, LimitFirst-1));
            //Console.WriteLine(strSql.ToString());
            return ExportDeal(strSql.ToString());
        }
        #endregion
    }
}
